package com.bckj.fastboot.upms.biz.mapper;

import com.bckj.fastboot.upms.api.dto.ClientAuthInfo;
import com.bckj.fastboot.upms.api.entity.SysOauthClientDetails;
import com.bckj.fastboot.upms.api.vo.SysOauthClientDetailsVO;
import com.bckj.fastboot.upms.api.dto.SysOauthClientDetailsQuery;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.jdbc.SQL;
import java.util.List;
import org.apache.ibatis.annotations.Mapper;

/**
 * 客户端信息表(SysOauthClientDetails)表数据库访问层
 *
 * @author wfc
 * @since 2023-09-11 17:38:49
 */
@Mapper
public interface SysOauthClientDetailsMapper extends BaseMapper<SysOauthClientDetails> {

    /**
      * 列表
      *
      * @param query req
      * @return list
      */
    @SelectProvider(method = "list" , type = SysOauthClientDetailsProvider.class)
    List<SysOauthClientDetailsVO> list(SysOauthClientDetailsQuery query);

    @Select("""
    select * from sys_oauth_client_details where client_id=#{clientId} and delete_flag=0 limit 1
    """)
    ClientAuthInfo findByClientId(@Param("clientId") String clientId);

    class SysOauthClientDetailsProvider{
        
        public String list(SysOauthClientDetailsQuery query){
            return new SQL(){{
                SELECT("id, client_id, client_secret, resource_ids, scope, authorized_grant_types, web_server_redirect_uri, authorities, access_token_validity, refresh_token_validity, additional_information, auto_approve, version, delete_flag, create_id, update_time, create_time");
                FROM("sys_oauth_client_details");
                ORDER_BY("id DESC");
            }}.toString();
        }
    }
}

